package 笔试.字节;

import org.junit.Test;

import java.util.Scanner;
import java.util.concurrent.Executors;

/**
 * @author:谢君臣
 * @Date:2021/8/24-10:16
 * @version:1.0
 * @function:
 */
public class Main1802 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] num = scanner.nextLine().split(" ");
        int n = Integer.parseInt(num[0]);
        int k = Integer.parseInt(num[1]);
        String line = scanner.nextLine();

        int length = line.length();
        int i = 0, j = 0, num_a = 0, num_b = 0;
        int res = 0;
        while (j < length && i < length) {
            while (i < length) {
                if (k < Math.min(num_a, num_b))
                    break;
                if (line.charAt(i) == 'a') {
                    num_a++;
                } else num_b++;
                i++;
            }
            res = Math.max(res, i - j -1); // 计算长度
            while (k < Math.min(num_a, num_b)){
                if (line.charAt(j) == 'a')
                    num_a--;
                else
                    num_b--;
                j++;
            }
        }
        System.out.println(res);
    }
}
